﻿using JetBrains.Annotations;
using Mt.Site.Core.WorkFlows.Diy.Plugin;
using Mt.Site.Core.WorkFlows.Enum;
using Mt.Site.Core.WorkFlows.Process.Entities;
using Mt.Site.Core.WorkFlows.Process.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Mt.Site.Core.WorkFlows.Process.Stores
{
    public interface IWorkFlowFormDataStore
    {
        IQueryable<WorkFlowPaperData> WorkFlowPaperData { get; }

        Task<Dictionary<string, string>> GetAllFieldAsync(Guid paperId);
        Task<Dictionary<string, string>> GetSpecialFieldAsync(List<string> fieldName, Guid paperId);
        Task<string> GetSpecialFieldAsync(string fieldName, Guid paperId);

        Task UpdateSpecialFieldAsync(string fieldName, Guid paperId, string value);

        Task UpdateOrInsertSpecialFieldAsync(string fieldName, Guid paperId, string value);

        /// <summary>
        /// 稿件详情页 表单数据读取
        /// </summary>
        /// <returns></returns>
        Task<GetFormDataOutput> GetFormDataForEditAsync(IWorkFlowManager workFlowManager);

        /// <summary>
        /// 表单字段的编辑权限查询
        /// </summary>
        /// <param name="workflow"></param>
        /// <param name="curentNodeId"></param>
        /// <returns></returns>
        Task<List<FormDataItemDescription>> GetFieldPermissionAsync(
            [NotNull]IWorkflowDefinition workflow,
            Guid curentNodeId,
            IWorkFlowManager workFlowManager);

        /// <summary>
        /// 详情页更新表单
        /// </summary>
        /// <returns></returns>
        Task UpdateAsync(Dictionary<string, string> values, IWorkFlowManager workFlowManager);

        /// <summary>
        /// 管理员维护
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="workflow"></param>
        /// <param name="curentNodeId"></param>
        /// <param name="authorUserId"></param>
        /// <returns></returns>
        Task<GetFormDataOutput> GetFormDataForSuperEditAsync(
            Guid paperId,
            IWorkflowDefinition workflow,
            Guid curentNodeId,
            long authorUserId);

        /// <summary>
        /// 管理员更新
        /// </summary>
        /// <param name="values"></param>
        /// <param name="paperId"></param>
        /// <param name="workflow"></param>
        /// <param name="curentNodeId"></param>
        /// <returns></returns>
        Task SuperUpdateAsync(
            Dictionary<string, string> values,
            Guid paperId,
            IWorkflowDefinition workflow,
            Guid curentNodeId);

        /// <summary>
        /// 打印页或归档页等拉取表单数据
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="workflow"></param>
        /// <param name="curentNodeId"></param>
        /// <param name="authorUserId"></param>
        /// <returns></returns>
        Task<GetFormDataOutput> GetFormDataForReadOnlyAsync(
            Guid paperId,
            IWorkflowDefinition workflow,
            Guid curentNodeId,
            long authorUserId);
    }
}
